using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using XiaoGang.Soft.XGWMS.COM;
using XiaoGang.Soft.XGWMS.MODEL;

namespace XiaoGang.Soft.XGWMS.DAL_SQL
{
    public class DAL_ComProcess
    {
        /// <summary>
        /// Get_MaxID
        /// </summary>
        /// <param name="GETID_DIV"></param>
        /// <param name="FISCAL_YEAR"></param>
        /// <param name="connection"></param>
        /// <returns></returns>
        public ReturnValue Get_MaxID(string GETID_DIV, string FISCAL_YEAR)
        {
            SqlParameter[] parameters = {
                new SqlParameter("@GETID_DIV", SqlDbType.Char,2),
                new SqlParameter("@FISCAL_YEAR", SqlDbType.Char,4)};
            parameters[0].Value = GETID_DIV;
            parameters[1].Value = FISCAL_YEAR;
            return DBUtility.SqlHelper.Query(DAL_ComProcess_SQL.Get_MaxID, parameters);
        }

        /// <summary>
        /// Get_MaxID
        /// </summary>
        /// <param name="GETID_DIV"></param>
        /// <param name="FISCAL_YEAR"></param>
        /// <param name="connection"></param>
        /// <returns></returns>
        public static bool GetUniqueNo(string UPDATER_ID, string TERMINAL_CD, string GETID_DIV, string FISCAL_YEAR, out string UniqueNo)
        {
            SqlParameter[] parameters = {new SqlParameter("@UpdaterID",SqlDbType.VarChar,12),
                new SqlParameter("@TerminalID",SqlDbType.VarChar,256),
                new SqlParameter("@GetIDType", SqlDbType.Char,2),
                new SqlParameter("@FiscalYear", SqlDbType.Char,4),
                new SqlParameter("@NewNo", SqlDbType.VarChar,12)};
            parameters[0].Value = UPDATER_ID;
            parameters[1].Value = TERMINAL_CD;
            parameters[2].Value = GETID_DIV;
            parameters[3].Value = FISCAL_YEAR;
            parameters[4].Direction = ParameterDirection.Output;
            ReturnValue resoult = DBUtility.SqlHelper.ExeProcedure("spCreatUniqueNo", parameters);
            UniqueNo = parameters[4].Value.ToString();
            return resoult.IsSuccess;
        }

        /// <summary>
        /// Check_Exist_MaxID
        /// </summary>
        /// <param name="GETID_DIV"></param>
        /// <param name="FISCAL_YEAR"></param>
        /// <returns></returns>
        public ReturnValue Check_Exist_MaxID(string GETID_DIV, string FISCAL_YEAR)
        {
            SqlParameter[] parameters = {
                new SqlParameter("@GETID_DIV", SqlDbType.Char,2),
                new SqlParameter("@FISCAL_YEAR", SqlDbType.Char,4)};
            parameters[0].Value = GETID_DIV;
            parameters[1].Value = FISCAL_YEAR;
            return DBUtility.SqlHelper.Query(DAL_ComProcess_SQL.Check_Exist_MaxID, parameters);
        }

        /// <summary>
        /// Update_MaxID
        /// </summary>
        /// <param name="modGetID"></param>
        /// <returns></returns>
        public ReturnValue Update_GetID(MOD_M011_GET_ID modGetID)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@UPDATER_ID", SqlDbType.VarChar,12),
                    new SqlParameter("@TERMINAL_CD", SqlDbType.VarChar,256),
                    new SqlParameter("@GETID_DIV", SqlDbType.Char,2),
                    new SqlParameter("@FISCAL_YEAR", SqlDbType.Char,4),
                    new SqlParameter("@NEWEST_NO", SqlDbType.Int,4)};
            parameters[0].Value = modGetID.UPDATER_ID;
            parameters[1].Value = modGetID.TERMINAL_CD;
            parameters[2].Value = modGetID.GETID_DIV;
            parameters[3].Value = modGetID.FISCAL_YEAR;
            parameters[4].Value = modGetID.NEWEST_NO;
            return DBUtility.SqlHelper.ExecuteSql(DAL_ComProcess_SQL.Update_MaxID, parameters);
        }

        /// <summary>
        /// Add_GetID
        /// </summary>
        /// <param name="modGetID"></param>
        /// <returns></returns>
        public ReturnValue Add_GetID(MOD_M011_GET_ID modGetID)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@UPDATER_ID", SqlDbType.VarChar,12),
                    new SqlParameter("@TERMINAL_CD", SqlDbType.VarChar,256),
                    new SqlParameter("@GETID_DIV", SqlDbType.Char,2),
                    new SqlParameter("@FISCAL_YEAR", SqlDbType.Char,4),
                    new SqlParameter("@START_NO", SqlDbType.Int,4),
                    new SqlParameter("@END_NO", SqlDbType.Int,4),
                    new SqlParameter("@NEWEST_NO", SqlDbType.Int,4)};
            parameters[0].Value = modGetID.UPDATER_ID;
            parameters[1].Value = modGetID.TERMINAL_CD;
            parameters[2].Value = modGetID.GETID_DIV;
            parameters[3].Value = modGetID.FISCAL_YEAR;
            parameters[4].Value = modGetID.START_NO;
            parameters[5].Value = modGetID.END_NO;
            parameters[6].Value = modGetID.NEWEST_NO;
            return DBUtility.SqlHelper.ExecuteSql(DAL_ComProcess_SQL.Add_MaxID, parameters);
        }
    }
}
